package com.qf.dao.daoImpl;

import com.alibaba.druid.pool.DruidDataSource;
import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.util.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    DruidDataSource dateSource = DBUtil.getDateSource();
    QueryRunner qr = new QueryRunner(dateSource);

    @Override
    public User FindUserByName(String username) {
        String sql ="select * from t_user where username =?";
        try {
           return qr.query(sql,new BeanHandler<User>(User.class),username);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int addUser(User user) {
        String sql = "insert into t_user (username , password ,status) value(?,?,?)";
        try {
            return  qr.update(sql, user.getUsername(), user.getPassword(), user.getStatus());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}
